package hk.m4s.lr.repair.test.ui.goods;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import framework.common.Constant;
import framework.common.baseui.UeBaseActivity;
import framework.common.zanetwork.core.ResponseCallback;
import framework.utils.SharedPreferencesUtils;
import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.FlashSaleModel;
import hk.m4s.lr.repair.test.ui.adapter.FlashSaleListAdapter;
import hk.m4s.lr.repair.test.views.InnerGridView;
import okhttp3.Response;

/**
 * Created by qi.wang on 2017/5/10.
 * 商品促销展示页
 */

public class ShopRecommedActivity extends UeBaseActivity {
    private ImageView redcommedImg;
    private InnerGridView innerGridView;
    //public static List<MakingModel> likeList = new ArrayList<>();
   // private MakingGoodsAdapter carShopLikeAdapter;
    private Context context;
    private String goodsId = "";
    private String goodsUrl = "";
    private String makingid;
    private FlashSaleListAdapter adapter;
    private List<FlashSaleModel>flashSaleModelList=new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        baseSetContentView(R.layout.activity_shop_recommened);
        hiddenFooter();
        showGoBackBtn();
        setTitleText("深秋换季大促销");
        makingid = getIntent().getStringExtra("goods_id");
        goodsUrl = getIntent().getStringExtra("goodsUrl");
        context = this;

        findBaseView();

    }

    public void findBaseView() {
        redcommedImg = (ImageView) findViewById(R.id.redcommedImg);
        innerGridView = (InnerGridView) findViewById(R.id.vlist);

        innerGridView.setOnItemClickListener(clickItem);
        adapter=new FlashSaleListAdapter(mContext,flashSaleModelList);
        innerGridView.setAdapter(adapter);
       // carShopLikeAdapter = new MakingGoodsAdapter(context, likeList);
        //innerGridView.setAdapter(carShopLikeAdapter);
        //findMakingGoods();
        showInfo();
    }
    public void showInfo(){
        for(int i=0;i<10;i++){
            FlashSaleModel model=new FlashSaleModel();
            model.setGoodsName("职业套装欧美条纹西服");
            model.setGoodsOldPrice("220");
            model.setGoodsPrice("118");
            model.setGoodsSale("12");
            flashSaleModelList.add(model);
        }
        adapter.notifyDataSetChanged();
    }

    AdapterView.OnItemClickListener clickItem = new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                long arg3) {
            // TODO Auto-generated method stub
//            MakingModel model = likeList.get(arg2);
//            Intent in = new Intent(ShopRecommedActivity.this, GoodsEventActivity.class);
//            in.putExtra("goods_id", model.getGoodsid());
//            startActivity(in);

        }

    };

    public void showImage(TextView myTextview, int resId) {
        Drawable drawable = getResources().getDrawable(resId);//注意查看方法
        // TextView.setCompoundDrawables(Drawable, Drawable, Drawable, Drawable)
        //的注释，要求设置的drawable必须已经通过Drawable.setBounds方法设置过边界参数
        //所以，此种方式下该行必不可少
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        myTextview.setCompoundDrawables(null, null, drawable, null);
    }

//    public void findMakingGoods() {
//        Map<String, Object> parmas = new HashMap<>();
//        parmas.put("device_type", Constant.device_type);
//        parmas.put("userId", SharedPreferencesUtils.getSharedPreferences(Constant.userId, ""));
//        parmas.put("token", SharedPreferencesUtils.getSharedPreferences(Constant.token, ""));
//        parmas.put("makingId", makingid);
//        AccountSerive.findMakingGoods(context, parmas, new ResponseCallback<MakingModel>() {
//            @Override
//            public void onSuccess(MakingModel userinfoModel) {
//                likeList.clear();
//                if (userinfoModel != null) {
//                    if (userinfoModel.getDeepimg() != null) {
//                        Glide.with(context).load(userinfoModel.getDeepimg()).asBitmap().placeholder(R.mipmap.default1).error(R.mipmap.default1).into(redcommedImg);
//                    }
//
//                    if (userinfoModel.getList() != null) {
//                        likeList.addAll(userinfoModel.getList());
//                        carShopLikeAdapter.notifyDataSetChanged();
//                    }
//                }
//            }
//
//            @Override
//            public void onError(Response response, int errorCode, String errorMsg, Exception e) {
//
//            }
//        });
//
//    }
}
